package com.lsh.controller;

import com.lsh.entity.Result;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/getUsername")
    public Result getUsername(){
        User userInfo = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return new Result(true,"登录名获取成功",userInfo.getUsername());
    }
}
